﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MadLibrary.Managing.Persons
{
    /// <summary>
    /// Holds and manages person.
    /// </summary>
    public class Person : IBuildable
    {
        /// <summary>
        /// Gets the full name.
        /// </summary>
        public string Name
        {
            get
            {
                return this.Firstname + " " + this.Surname;
            }
        }

        /// <summary>
        /// Gets or sets the age.
        /// </summary>
        /// <value>
        /// The age.
        /// </value>
        public int Age { get; set; }

        /// <summary>
        /// Gets or sets the firstname.
        /// </summary>
        /// <value>
        /// The firstname.
        /// </value>
        public string Firstname { get; set; }

        /// <summary>
        /// Gets or sets the surname.
        /// </summary>
        /// <value>
        /// The surname.
        /// </value>
        public string Surname { get; set; }

        /// <summary>
        /// Gets or sets the residence.
        /// </summary>
        /// <value>
        /// The residence.
        /// </value>
        public Residence Residence { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="Person"/> class.
        /// </summary>
        public Person()
        {
            this.Firstname = "";
            this.Surname = "";
            this.Age = 1;
            this.Residence = new Residence();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Person"/> class.
        /// </summary>
        /// <param name="FullName">The full name.</param>
        public Person(string FullName)
        {
            this.Firstname = FullName.Split(' ')[0];
            this.Surname = FullName.Remove(0, FullName.IndexOf(' '));
            this.Age = 1;
            this.Residence = new Residence();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Person"/> class.
        /// </summary>
        /// <param name="Firstname">The firstname.</param>
        /// <param name="Surname">The surname.</param>
        public Person(string Firstname, string Surname)
        {
            this.Firstname = Firstname;
            this.Surname = Surname;
            this.Age = 1;
            this.Residence = new Residence();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Person"/> class.
        /// </summary>
        /// <param name="FullName">The full name.</param>
        /// <param name="Age">The age.</param>
        public Person(string FullName, int Age)
        {
            this.Firstname = FullName.Split(' ')[0];
            this.Surname = FullName.Remove(0, FullName.IndexOf(' '));
            this.Age = Age;
            this.Residence = new Residence();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Person"/> class.
        /// </summary>
        /// <param name="FullName">The full name.</param>
        /// <param name="Age">The age.</param>
        /// <param name="Residence">The residence.</param>
        public Person(string FullName, int Age, Residence Residence)
        {
            this.Firstname = FullName.Split(' ')[0];
            this.Surname = FullName.Remove(0, FullName.IndexOf(' '));
            this.Age = 1;
            this.Residence = Residence;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Person"/> class.
        /// </summary>
        /// <param name="Firstname">The firstname.</param>
        /// <param name="Surname">The surname.</param>
        /// <param name="Age">The age.</param>
        public Person(string Firstname, string Surname, int Age)
        {
            this.Firstname = Firstname;
            this.Surname = Surname;
            this.Age = Age;
            this.Residence = new Residence();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Person"/> class.
        /// </summary>
        /// <param name="Firstname">The first name.</param>
        /// <param name="Surname">The surname.</param>
        /// <param name="Age">The age.</param>
        /// <param name="Residence">The residence.</param>
        public Person(string Firstname, string Surname, int Age, Residence Residence)
        {
            this.Firstname = Firstname;
            this.Surname = Surname;
            this.Age = Age;
            this.Residence = Residence;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return this.GetPersonInfo();
        }

        /// <summary>
        /// Gets the person info.
        /// </summary>
        /// <returns>String person info.</returns>
        public string GetPersonInfo()
        {
            return String.Format("Full name: {0}\r\nAge: {1}\r\nResidence: {2}", this.Name, this.Age.ToString(), this.Residence.ToString());
        }

        /// <summary>
        /// Builds object into string.
        /// </summary>
        /// <returns>
        /// Built string.
        /// </returns>
        string IBuildable.Build()
        {
            return this.GetPersonInfo();
        }
    }
}